package datastructure.selfexercise;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;

/**
 * @Author Gan
 * @Date 2021/5/7 20:45
 * @Description: 输入: s = "abcabcbb"
 * 输出: 3
 * 解释: 因为无重复字符的最长子串是 "abc"，所以其长度为 3。
 */
public class Junit {
    public static void main(String[] args) {

    }

    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        boolean flag = false;
        ListNode head;
        if ((l1.val + l2.val) > 9) {
            int data = (l1.val + l2.val) % 10;
            head = new ListNode(data, null);
            flag = true;
        } else {
            head = new ListNode((l1.val + l2.val), null);
        }
        l1 = l1.next;
        l2 = l2.next;
        while (l1 != null && l2 != null) {
            if (flag == true) {
                if ((l1.val + l2.val + 1) > 9) {
                    int data = (l1.val + l2.val + 1) % 10;
                    head.next = new ListNode(data, null);
                    flag = true;
                } else {
                    head.next = new ListNode((l1.val + l2.val + 1), null);
                }
                flag = false;
            } else {
                if ((l1.val + l2.val) > 9) {
                    int data = (l1.val + l2.val) % 10;
                    head.next = new ListNode(data, null);
                    flag = true;
                } else {
                    head.next = new ListNode((l1.val + l2.val), null);
                }
            }
        }
        return null;
    }

    class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }

    }

}
